from appium import webdriver
from appium.webdriver.common.appiumby import By
import time

des = {
    "platformName": "Android",
    "appium:platformVersion": "7.1.2",
    "appium:deviceName": "emulator-5554",
    "udid": "emulator-5554",
    "appPackage": "com.android.settings",
    "appActivity": ".Settings"
}

# 初始化驱动对象
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', des)
time.sleep(2)
# # 定位搜索按钮
# search_button_element = driver.find_element(By.ID, "com.android.settings:id/search")
# # 点击搜索按钮
# search_button_element.click()
# time.sleep(2)

# # 定位搜索输入框元素
# search_input_element = driver.find_element(By.CLASS_NAME, "android:id/search_src_text")
# # 输入：蓝牙
# search_input_element.send_keys("蓝牙")

# # 点击-蓝牙
# driver.find_element(By.XPATH, "//*[@text='蓝牙']").click()

elements = driver.find_elements(By.ID, "android:id/title")
for ele in elements:
    print(ele.text)

time.sleep(5)
driver.quit()